package com.jzit168.library_retrofit.common

import com.jzit168.library_retrofit.exception.RequestException

/**
 *@Desc: 网络请求返回的数据格式的通用部分
 *@Author: Android Developer
 *@Date: 2020/10/15
 *@sample
 *  {
 *      "code": 0,
 *      "message": "加载成功",
 *      "data": {}
 *  }
 *
 **/

data class JzResult<T>(
    val code: Int,
    val message: String,
    val data: T
) {
    fun success() = when (code) {
        APICode.SUCCESS -> {
            data
        }
        else -> {
            throw RequestException(code, message)
        }
    }
}